//
//  zixunViewController.m
//  movie
//
//  Created by 白浩洋 on 2018/4/8.
//  Copyright © 2018年 白浩洋. All rights reserved.
//

#import "zixunViewController.h"

@interface zixunViewController ()
@property (nonatomic,strong)UIWebView *webView;
@end

@implementation zixunViewController
{
    NSString *content;
    BOOL shoucang;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    if(self.type != 100){
    shoucang = NO;
    [self setupRightImage:[UIImage imageNamed:@"bbtt_noshoucang"] action:@selector(shoucangClick)];
    for(NSDictionary *dic in [NBATools getshenheshoucang]){
        if([dic[@"url"] isEqualToString:self.url]){
             [self setupRightImage:[UIImage imageNamed:@"bbtt_shoucang"] action:@selector(shoucangClick)];
            shoucang = YES;
            break;
        }
    }
    }
    [SVProgressHUD showInfoWithStatus:@"正在加载,请稍后"];
    [self addCustomBackBarButtonItemWithTarget:self action:@selector(backUp)];
    [self requestData];
    
}
- (void)shoucangClick{
    if(shoucang){
        NSArray *arrrrr=[NBATools getshenheshoucang];
        for(int i = 0 ;i < arrrrr.count ; i++){
            NSDictionary *dic = arrrrr[i];
            if([dic[@"url"] isEqualToString:self.url]){
                [self setupRightImage:[UIImage imageNamed:@"bbtt_noshoucang"] action:@selector(shoucangClick)];
                NSMutableArray *arr = [NSMutableArray arrayWithArray:[NBATools getshenheshoucang]];
                [arr removeObjectAtIndex:i];
                break;
            }
        }
    }else{
         NSMutableArray *arr = [NSMutableArray arrayWithArray:[NBATools getshenheshoucang]];
         NSDictionary *dic =@{@"url":self.url,@"dic":self.dic};
        [arr insertObject:dic atIndex:0];
        [NBATools setshenheshoucang:arr];
        [self setupRightImage:[UIImage imageNamed:@"bbtt_shoucang"] action:@selector(shoucangClick)];
    }
}
- (void)requestData{
    [HYBNetworking postWithUrl:self.url refreshCache:YES params:nil success:^(id response) {
        NSDictionary *dic = [response objectForKey:@"resMsg"];
        NSDictionary *dataDic = [dic objectForKey:@"details"];
        content  = dataDic[@"content"];
        [self addCustomTitleWithTitle:dataDic[@"title"]];
        [self.webView loadHTMLString:content baseURL:nil];
        [SVProgressHUD dismiss];
    } fail:^(NSError *error) {
        
    }];
}
- (void)backUp{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)loadString:(NSString *)str{
    // 1. URL 定位资源,需要资源的地址
    NSURL *url = [NSURL URLWithString:str];
    // 2. 把URL告诉给服务器,请求,从m.baidu.com请求数据
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    // 3. 发送请求给服务器
    [self.webView loadRequest:request];
}
- (UIWebView *)webView   {
    if (!_webView) {
        _webView = [[UIWebView alloc] initWithFrame:CGRectMake(PXChange(20), PXChange(20), ScreenWidth-PXChange(20), self.view.height - PXChange(40))];
        _webView.backgroundColor = [UIColor whiteColor];
        _webView.dataDetectorTypes = UIDataDetectorTypeAll;
        _webView.scalesPageToFit = YES;//自动对页面进行缩放以适应屏幕
        [self.view addSubview:_webView];
    }
    return _webView;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
